package com.shushan.home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.common.ui.LimitScrollerView;
import com.shushan.home.bean.BannerDataBean;
import com.shushan.shushanbao.R;
import com.shushan.util.ImageUtils;
import com.shushan.util.ToolUtils;

import java.util.List;

/**
 * @ClassName: HomeLimitScrollAdapter
 * @Desciption: //TODO
 * @author: yichaohua
 * @date: 2018-12-08
 */
public class HomeLimitScrollAdapter implements LimitScrollerView.LimitScrollAdapter{

    private Context context;
    private List<BannerDataBean> bannerDataBeanList;

    public HomeLimitScrollAdapter(Context context) {
        this.context = context;
    }

    public HomeLimitScrollAdapter(Context context, List<BannerDataBean> bannerDataBeanList) {
        this.context = context;
        this.bannerDataBeanList = bannerDataBeanList;
    }

    @Override
    public int getCount() {
        return ToolUtils.isListEmpty(bannerDataBeanList)?0:bannerDataBeanList.size();
    }

    @Override
    public View getView(int index) {
        BannerDataBean bannerDataBean = bannerDataBeanList.get(index);

        View itemView = LayoutInflater.from(context).inflate(R.layout.home_limit_scroller_item, null, false);
        ImageView imageView = itemView.findViewById(R.id.home_limit_img);
        ImageUtils.loadImagePlace(context,R.drawable.limit_scrool_icon,bannerDataBean.pic,imageView);
        TextView textView = itemView.findViewById(R.id.home_limit_tv);
        textView.setText(bannerDataBean.name);

        itemView.setTag(bannerDataBean);

        return itemView;
    }

    public List<BannerDataBean> getBannerDataBeanList() {
        return bannerDataBeanList;
    }

    public void setBannerDataBeanList(List<BannerDataBean> bannerDataBeanList) {
        this.bannerDataBeanList = bannerDataBeanList;
    }
}
